/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * Calculator
 * Copyright (C) Jeff Goodhue 2011 <jeff@JeffLinux>
 * 
 * Calculator is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Calculator is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "graph-area.h"
#include <cairomm/context.h>

GraphArea::GraphArea(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& refGlade) : //Required to be hooked to the glade file.
Gtk::DrawingArea(cobject)
{
	x0 = 280.0; //Doesn't draw anything
	x1 = 280.0;
	y0 = 280.0;
	y1 = 280.0;
}

GraphArea::~GraphArea()
{
}

void GraphArea::setCoords(double a0, double b0, double a1, double b1) {
	x0 = a0;
	y0 = b0;
	x1 = a1;
	y1 = b1;
}

bool GraphArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr) {
	cr->set_source_rgb(0.0, 0.0, 0.0); //black
	cr->set_line_width(1.0);
	cr->move_to(140, 0);
	cr->line_to(140, 280);
	cr->move_to(0, 140);
	cr->line_to(280, 140);
	cr->stroke();
	cr->set_source_rgb(0.8, 0.0, 0.0); //red
	cr->set_line_width(5.0);
	cr->move_to(x0, y0);
	cr->line_to(x1, y1);
	cr->stroke();
}

void GraphArea::refresh() { //Calls on_draw...
	Glib::RefPtr<Gdk::Window> win = get_window();
    if (win)
    {
        Gdk::Rectangle r(0, 0, get_allocation().get_width(),
                get_allocation().get_height());
        win->invalidate_rect(r, false);
    }
}